package com.fx;

import com.fx.common.ExceptionHandler;
import com.fx.view.CustomerSplashScreen;
import com.fx.view.LoginPageView;
import com.github.lianjiatech.retrofit.spring.boot.annotation.RetrofitScan;
import de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.Collection;
import java.util.Collections;

/**
 * 参考：
 * https://segmentfault.com/a/1190000014037443
 * https://www.cnblogs.com/stars-one/p/10959878.html
 * https://www.cnblogs.com/6b7b5fc3/p/13054733.html
 */
@Slf4j
@RetrofitScan(basePackages="com.fx.common.api")
@SpringBootApplication
public class MainController extends AbstractJavaFxApplicationSupport{

    public static void main(String[] args) {
        launch(MainController.class, LoginPageView.class,new CustomerSplashScreen(),args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        //全屏模式
        //stage.setMaximized(true);
        Thread.setDefaultUncaughtExceptionHandler((t,e) -> {
            ExceptionHandler handler = context.getBean(ExceptionHandler.class);
            handler.showError(t,e);
        });
        super.start(stage);
    }

    @Override
    public void beforeInitialView(Stage stage, ConfigurableApplicationContext ctx) {
        stage.initStyle(StageStyle.TRANSPARENT);
        super.beforeInitialView(stage, ctx);
    }

    @Override
    public void beforeShowingSplash(Stage splashStage) {
        super.beforeShowingSplash(splashStage);
    }

    /**
     * 加载界面标题上图片
     * @return
     */
    @Override
    public Collection<Image> loadDefaultIcons() {
        return Collections.emptyList();
    }
}
